import { cloneDeep } from 'lodash-es'

export function isValidKey(key: string | number | symbol, object: object): key is keyof typeof object {
  return key in object
}

export function useForm<F extends object>(initValue: F) {
  const getInitValue = () => cloneDeep(initValue)

  const form = reactive(getInitValue())

  const resetForm = () => {
    for (const key in form) {
      if (isValidKey(key, form)) {
        // 处理...
        delete form[key]
      }
    }
    Object.assign(form, getInitValue())
  }

  return { form, resetForm }
}
